/*
 *    Copyright (c) 2018-2025, proj All rights reserved.
 *
 * Redistribution and use in source and binary forms, with or without
 * modification, are permitted provided that the following conditions are met:
 *
 * Redistributions of source code must retain the above copyright notice,
 * this list of conditions and the following disclaimer.
 * Redistributions in binary form must reproduce the above copyright
 * notice, this list of conditions and the following disclaimer in the
 * documentation and/or other materials provided with the distribution.
 * Neither the name of the proj developer nor the names of its
 * contributors may be used to endorse or promote products derived from
 * this software without specific prior written permission.
 * Author: proj
 */
package com.ykht.proj.coupon.service.impl;

import cn.hutool.core.bean.BeanUtil;
import com.baomidou.mybatisplus.core.toolkit.Wrappers;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.ykht.proj.coupon.Enum.CouponEnum;
import com.ykht.proj.coupon.entity.CnCouShop;
import com.ykht.proj.coupon.entity.CnCoupon;
import com.ykht.proj.coupon.entity.CnShop;
import com.ykht.proj.coupon.mapper.CnBrandMapper;
import com.ykht.proj.coupon.mapper.CnCouShopMapper;
import com.ykht.proj.coupon.mapper.CnCouponMapper;
import com.ykht.proj.coupon.mapper.CnShopMapper;
import com.ykht.proj.coupon.service.CnCouShopService;
import com.ykht.proj.coupon.vo.CnShopSimpleVo;
import lombok.RequiredArgsConstructor;
import org.springframework.stereotype.Service;

import java.util.ArrayList;
import java.util.List;

/**
 * 优惠券店铺中间表
 *
 * @author proj code generator
 * @date 2020-11-20 18:15:23
 */
@Service
@RequiredArgsConstructor
public class CnCouShopServiceImpl extends ServiceImpl<CnCouShopMapper, CnCouShop> implements CnCouShopService {

	private final CnCouShopMapper cnCouShopMapper;
	private final CnCouponMapper cnCouponMapper;
	private final CnShopMapper cnShopMapper;

	@Override
	public List<CnShopSimpleVo> findShop4CouponListByCouponId(Long id) {

		CnCoupon cnCoupon = cnCouponMapper.selectById(id);
		if (CouponEnum.currency.getValue().equals(cnCoupon.getType()))
			return this.findShopSimpleVoByBrandId(cnCoupon.getBrandId());
		else
			return cnCouShopMapper.findShop4CouponListByCouponId(id);
	}

	@Override
	public List<CnShopSimpleVo> findShop4CouponListByCouponIds(List<Long> ids) {
		return cnCouShopMapper.findShop4CouponListByCouponIds(ids);
	}

	@Override
	public List<CnShopSimpleVo> findShopSimpleVoByBrandId(Long brandId){
		List<CnShopSimpleVo> tempList = new ArrayList();
		cnShopMapper.selectList(Wrappers.lambdaQuery(CnShop.class)
				.eq(CnShop::getBrandId,brandId)
				.eq(CnShop::getDisplay,0)).forEach(o->{
			CnShopSimpleVo vo = new CnShopSimpleVo();
			vo.setId(o.getId());
			vo.setName(o.getName());
			tempList.add(vo);
		});
		return tempList;
	}

}
